<template>
  <div>
 <van-form @submit="zhuce">
      <van-field
        v-model="user.phone"
        name="账号"
        label="账号"
        placeholder="账号"
        :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
        v-model="user.nickname"
        name="昵称"
        label="昵称"
        placeholder="昵称"
        :rules="[{ required: true, message: '请填写昵称' }]"
      />
      <van-field
        v-model="user.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="danger" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {Toast} from "vant"
import {reqregister} from "../../http/http"
import axios from 'axios'
export default {
  data(){
    return{
        //1.初始化表单数据
        user:{
         phone:"",
         nickname:"",
         password:""
        }
    }
  },
  methods:{
    //2.点击注册按钮
    zhuce(){
        reqregister(this.user).then(res=>{
        console.log(res);
        if(res.data.code==200){
          //注册成功
          Toast(res.data.msg)
          //跳转登陆
          this.$router.push("login")
        }else{
          //注册失败
          Toast(res.data.msg)
        }
      })
    }
  }

}
</script>

<style>

</style>